//
//  RadioViewController.m
//  Boom
//
//  Created by Mr.Feng on 15/3/5.
//  Copyright (c) 2015年 lanou3g. All rights reserved.
//

#import "RadioViewController.h"

@interface RadioViewController ()

@end

@implementation RadioViewController
- (void)dealloc
{
    [_firstVC release];
    [_secondVC release];
    [super dealloc];
}
- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view.
    
    self.view.backgroundColor = [UIColor whiteColor];
    // 添加两个页面视图
    self.secondVC = [[SecondViewController alloc] init];
    [self addChildViewController:self.secondVC];
    [self.view addSubview:self.secondVC.view];
    [_secondVC release];
    self.firstVC = [[FirestViewController alloc] init];
    [self addChildViewController:self.firstVC];
    [self.view addSubview:self.firstVC.view];
    [_firstVC release];
    
    // 设置segment
    UISegmentedControl *segment = [[UISegmentedControl alloc] initWithItems:[NSArray arrayWithObjects:@"随便看看", @"语音搜索", nil]];
    segment.frame = CGRectMake(0, 0, 100, 30);
//    UIImage *segImage1 = [UIImage imageNamed:@"RaidoSegmentImage1.png"];
//    segImage1 = [segImage1 imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal];
//    UIImage *segImage2 = [UIImage imageNamed:@"RaidoSegmentImage2.png"];
//    segImage2 = [segImage2 imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal];
//    [segment setImage:segImage1 forSegmentAtIndex:0];
//    [segment setImage:segImage2 forSegmentAtIndex:1];
    segment.backgroundColor = [UIColor whiteColor];
    segment.tintColor = [UIColor colorWithRed:225 / 255.0 green:51 / 255.0 blue:41 / 255.0 alpha:1];
    self.navigationItem.titleView = segment;
    segment.selectedSegmentIndex = 0;
    
//    // 去掉边框
//    segment.tintColor = [UIColor clearColor];//去掉颜色,现在整个segment都看不见
//    NSDictionary* selectedTextAttributes = @{NSFontAttributeName:[UIFont boldSystemFontOfSize:16],
//                                             NSForegroundColorAttributeName: [UIColor whiteColor]};
//    [segment setTitleTextAttributes:selectedTextAttributes forState:UIControlStateSelected];//设置文字属性
//    NSDictionary* unselectedTextAttributes = @{NSFontAttributeName:[UIFont boldSystemFontOfSize:16],
//                                               NSForegroundColorAttributeName: [UIColor lightTextColor]};
//    [segment setTitleTextAttributes:unselectedTextAttributes forState:UIControlStateNormal];
    
//    [segment release];
    
    [segment addTarget:self action:@selector(changeView:) forControlEvents:UIControlEventValueChanged];
    
    UIImage *image = [UIImage imageNamed:@"discover_smart_song@2x.png"];
    image = [image imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal];
    self.navigationItem.rightBarButtonItem = [[UIBarButtonItem alloc] initWithImage:image style:UIBarButtonItemStylePlain target:self action:@selector(barButtonAction:)];
}
- (void)barButtonAction:(UIBarButtonItem *)bar
{
    UINavigationController *naVC = [[UINavigationController alloc] initWithRootViewController:[PlayerViewController sharePlayerDataHandel]];
    [PlayerViewController sharePlayerDataHandel].navigationController.navigationBarHidden = YES;
    
    if ([[PlayerViewController sharePlayerDataHandel].streamer isPlaying] == YES) {
        CABasicAnimation *basicAnimation2 = [CABasicAnimation animationWithKeyPath:@"transform.rotation"];
        basicAnimation2.fromValue = [NSNumber numberWithInt:0];
        basicAnimation2.toValue = [NSNumber numberWithInt:M_PI * 2];
        [basicAnimation2 setDuration:30];
        [basicAnimation2 setRepeatCount:NSIntegerMax];
        [[PlayerViewController sharePlayerDataHandel].myImageView.layer addAnimation:basicAnimation2 forKey:@"rotation"];
    }
    
    [self presentViewController:naVC animated:YES completion:^{
        
        
    }];
    [naVC release];
}
// 实现segment改变视图的方法
- (void)changeView:(UISegmentedControl *)segment
{
    if (segment.selectedSegmentIndex == 0) {
        [self.view bringSubviewToFront:self.firstVC.view];
    }
    if (segment.selectedSegmentIndex == 1) {
        [self.view bringSubviewToFront:self.secondVC.view];
    }
}
- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
